<?php

/**
 * @category   MM
 * @package    MM_Service
 */
class MM_Service_Admin_EventWeibo extends Mediad2_Service_Abstract
{
	/**
	 * 初始化
	 */
	public function init()
	{
		$this->setMapper('MM_Mapper_EventWeibo');
		$this->setModel('MM_Model_EventWeibo');
	}
	
	/**
	 * 更新微博
	 * @param int $ewbid
	 * @param array $params
	 * @return Mediad2_Model_Result
	 */
	public function updateWeibo($ewbid, array $params)
	{
		try {
			//获取指定id的event weibo
			$result = $this->find($ewbid);
			if ($result->getCode()==$result::CODE_FAILURE) return $result;
	
			//封装model
			$model = $result->getData();
			if (isset($params['name'])) $model->setName($params['name']);
			if (isset($params['wbtype'])) $model->setWbtype($params['wbtype']);
			if (isset($params['wbuid'])) $model->setWbuid($params['wbuid']);
			if (isset($params['url'])) $model->setUrl($params['url']);
			if (isset($params['num'])) $model->setNum($params['num']);
			if (isset($params['location'])) $model->setLocation($params['location']);
			if (isset($params['avatar'])) $model->setAvatar($params['avatar']);

			return $this->update($model);
	
		} catch (Zend_Exception $e) {
			$this->handleException($e); //出错处理
			return $this->returnResult(Mediad2_Model_Result::CODE_FAILURE); //返回结果--失败
		}
	}
	
	/**
	 * 获得Weibo Type
	 */
	public function getWeiboType()
	{
		try {
			$dictUtil = Mediad2_Service_Util_Dict::getInstance();
			$result = $dictUtil->getId('wbtype');
			return $this->returnResult(Mediad2_Model_Result::CODE_SUCCESS,null,$result);
		} catch(Zend_Exception $e) {
			$this->handleException($e); //出错处理
			return $this->returnResult(Mediad2_Model_Result::CODE_FAILURE);	//返回结果--失败
		}
	}
	
}